<script>
  import { normal_option } from '../common'
  import Base from './Base'

  export default {
    name: 'ChartRelation',
    mixins: [Base],
    data() {
      return {
        defaultOption: {
          ...normal_option,
          tooltip: {
            formatter: function(params) {
              return params.dataType === 'node' ? params.name : ''
            }
          },
          legend: {
            show: true
          },
          series: []
        },
        defaultSeries: {
          type: 'graph',
          name: '',
          layout: 'force',
          zoom: 0.1,
          data: [],
          links: [],
          categories: [],
          roam: true,
          force: {
            repulsion: 300,
            gravity: 0.01,
            layoutAnimation: true
          },
          draggable: true,
          label: {
            show: true,
            position: 'right',
            formatter: '{b}',
            color: '#909399'
          },
          labelLayout: {
            hideOverlap: true
          },
          scaleLimit: {
            min: 0.4,
            max: 2
          },
          lineStyle: {
            color: 'source',
            curveness: 0.3
          }
        }
      }
    },
    computed: {
      option: function() {
        let series = []

        series.push({
          ...this.defaultSeries,
          data: this.dataset.common.nodes,
          links: this.dataset.common.links,
          categories: this.dataset.common.categories || [],
          edgeLabel: {
            show: true,
            position: 'end',
            color: '#fff'
          }
        })

        return {
          ...this.defaultOption,
          dataset: this.dataset,
          series
        }
      }
    }
  }
</script>
